import request from '@/utils/request'

export function changeSheetName (conditionSheetId: string, conditionSheetName: string) {
  return request({
    url: '/updateConditionSheetName',
    method: 'post',
    data: {
      conditionSheetId,
      conditionSheetName
    }
  })
}

export function createSheet (authorId: string, conditionSheetName: string, conditions: []) {
  return request({
    url: '/insertConditionSheet',
    method: 'post',
    data: {
      authorId,
      conditionSheetName,
      conditions
    }
  })
}

export function getConditions (conditionSheetId: string) {
  return request({
    url: '/offConditionSheetDetail',
    method: 'post',
    data: {
      conditionSheetId
    }
  })
}

export function getListConditions () {
  return request({
    url: '/listConditions',
    method: 'post'
  })
}

export function getSheets (userId: string) {
  return request({
    url: '/conditionSheetWarehouse',
    method: 'post',
    data: {
      userId
    }
  })
}

export function deleteSheet (conditionSheetId: string) {
  return request({
    url: '/deleteConditionSheet',
    method: 'post',
    data: {
      conditionSheetId
    }
  })
}

export function backtest (conditionSheetId: string, backTestStock: string, startTime: string, endTime: string) {
  return request({
    url: '/backTest',
    method: 'post',
    timeout: 120000,
    data: {
      conditionSheetId,
      backTestStock,
      startTime,
      endTime
    }
  })
}

export function saveBackTestReport (conditionSheetId: string, backTestStock: string, startTime: string, endTime: string, backTestYield: number) {
  return request({
    url: '/saveBackTestReport',
    method: 'post',
    timeout: 15000,
    data: {
      conditionSheetId,
      backTestStock,
      startTime,
      endTime,
      backTestYield
    }
  })
}

export function applyForShelf (conditionSheetId: string, commodityName: string, commodityDescription: string, commodityPrice: number, authorId: string) {
  return request({
    url: '/checkConditionSheet',
    method: 'post',
    timeout: 15000,
    data: {
      conditionSheetId,
      commodityName,
      commodityDescription,
      commodityPrice,
      authorId
    }
  })
}

export function getReportList (userId: string) {
  return request({
    url: '/listAllBackTestReports',
    method: 'post',
    timeout: 15000,
    data: {
      userId
    }
  })
}

export function getAllStocks () {
  return request({
    url: '/listAllStocks',
    method: 'post',
    timeout: 15000,
    data: {
    }
  })
}
